#-*- coding: utf-8 -*-
'''
Created on Aug 24, 2012

@author: bbg
'''

from sqlalchemy import Integer, Column, String, MetaData, Table, BLOB
from sqlalchemy.orm import mapper

class ShopGroup(object):
    '''
    分店群组信息
    '''
    
    _Mapper_ = None
    _company_id_ = -1    

    def __init__(self):
        self.id = 0
        self.name = ''                
            
    @staticmethod
    def doMapping(company_id):
        '''
        按company_id分库，每次生成对象前都要执行一次，以便map到正确的数据库上去
        '''
        if ShopGroup._company_id_ == company_id:
            return
                
        if ShopGroup._Mapper_ is not None:
            ShopGroup._Mapper_.dispose()
            
        metaData = MetaData()
        tableDefine = Table('shop_group', metaData,
                           Column('id', Integer, primary_key = True, autoincrement = True),
                           Column('name', String),
                            schema = "company_%s" % company_id)
                
        ShopGroup._Mapper_ = mapper(ShopGroup, tableDefine)
        
